home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / sswitchxp152.exe / source / SpeedswitchXP / Toptions.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-14  |  4.6 KB  |  156 lines

  1. /*
  2.    SpeedswitchXP V1.5
  3.    - Windows XP CPU Frequency Control for Notebooks -
  4.  
  5.    Copyright(c) 2002-2005 Christian Diefer
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License version 2 as 
  9.    published by the Free Software Foundation.
  10.    
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.    
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #define _UNICODE
  22.  
  23. #include "stdafx.h"
  24. #include "AtlBase.h"
  25. #include "TOptions.h"
  26.  
  27. #define WRITEDW(a,b)      \
  28.     if( key.SetValue(b,REG_DWORD,&(a),size) != ERROR_SUCCESS ) \
  29.     { \
  30.       key.Close(); \
  31.       return false; \
  32.     }
  33.  
  34. #define READDW(a,b) \
  35.     if( key.QueryValue(b,NULL,&(a),&size) != ERROR_SUCCESS ) \
  36.     { \
  37.       WRITEDW(a,b) \
  38.     }
  39.  
  40.  
  41. TOptions::TOptions()
  42. {
  43.   // initial (default) settings:
  44.   autoStart = true;     // autostart enabled
  45.   debugMode = false;    // use only on erratic behaviour for debugging
  46.   minimizeOnClose = false;
  47.   checkStatus = true;
  48.   checkInterval = 5;
  49.   reactivate = false;
  50.   originalScheme = 0;
  51.   readCPUSpeed = false;
  52.   speedMethod = 1;
  53.   readCPULoad = false;
  54.   showDiagram = false;
  55.   cpuInterval = 2;
  56.   freqScaling = 1;
  57.   showBattery = true;
  58.   batteryMethod = 0;      // show only when on DC
  59.   batteryIndicator = 0;   // show percentage (0); 1= show time left
  60.   maxSpeed = 0;
  61.   ac = true;
  62.   chargeIndicator = true; // show charging status
  63.   speedIcon = false;
  64.   loadIcon = false;
  65.   iconColor1 = 0;
  66.   iconColor2 = 15;
  67.   iconTransparent = TRUE;
  68. }
  69.  
  70. // read options from registry
  71. bool TOptions::getRegKeys()
  72. {
  73.   LONG lReturn = 0;
  74.   CRegKey key;
  75.   ULONG size = sizeof DWORD;   // DWORD size
  76.  
  77.  
  78.   lReturn = key.Create( HKEY_CURRENT_USER, _T("Software\\CD\\SpeedswitchXP\\") );
  79.  
  80.   if( lReturn == ERROR_SUCCESS )
  81.   {
  82.     READDW(autoStart,_T("Autostart"))
  83.     READDW(debugMode,_T("DebugMode"))
  84.     READDW(minimizeOnClose,_T("MinimizeOnClose"))
  85.     READDW(checkStatus,_T("CheckStatus"))
  86.     READDW(checkInterval,_T("CheckInterval"))
  87.     READDW(reactivate,_T("ReactivatePreviousScheme"))
  88.     READDW(originalScheme,_T("OriginalScheme"))
  89.     READDW(readCPUSpeed,_T("ReadCPUSpeed"))
  90.     READDW(speedMethod,_T("SpeedMethod"))
  91.     READDW(readCPULoad,_T("ReadCPULoad"))
  92.     READDW(showDiagram,_T("ShowDiagram"))
  93.     READDW(cpuInterval,_T("UpdateInterval"))
  94.     READDW(freqScaling,_T("FrequenceScaling"))
  95.     READDW(maxSpeed,_T("CalculatedMaxSpeed"))
  96.     READDW(showBattery,_T("ShowBattery"))
  97.     READDW(batteryMethod,_T("BatteryMethod"))
  98.     READDW(batteryIndicator,_T("BatteryIndicator"))
  99.     READDW(chargeIndicator,_T("ChargeIndicator"))
  100.     READDW(speedIcon,_T("TraySpeed"))
  101.     READDW(loadIcon,_T("TrayLoad"))
  102.     READDW(iconColor1,_T("IconColor1"))
  103.     READDW(iconColor2,_T("IconColor2"))
  104.     READDW(iconTransparent,_T("IconTransparent"))
  105.   }
  106.   else
  107.     return false;
  108.  
  109.   key.Close();
  110.   return true;
  111. }
  112.  
  113. // save options in registry
  114. bool TOptions::setRegKeys()
  115. {
  116.   LONG lReturn = 0;
  117.   CRegKey key;
  118.   ULONG size = sizeof DWORD;
  119.  
  120.   lReturn = key.Create( HKEY_CURRENT_USER, _T("Software\\CD\\SpeedswitchXP\\") );
  121.  
  122.   if( lReturn == ERROR_SUCCESS )
  123.   {
  124.     WRITEDW(autoStart,_T("Autostart"))
  125.     WRITEDW(debugMode,_T("DebugMode"))
  126.     WRITEDW(minimizeOnClose,_T("MinimizeOnClose"))
  127.     WRITEDW(checkStatus,_T("CheckStatus"))
  128.     WRITEDW(checkInterval,_T("CheckInterval"))
  129.     WRITEDW(reactivate,_T("ReactivatePreviousScheme"))
  130.     WRITEDW(originalScheme,_T("OriginalScheme"))
  131.     WRITEDW(readCPUSpeed,_T("ReadCPUSpeed"))
  132.     WRITEDW(speedMethod,_T("SpeedMethod"))
  133.     WRITEDW(readCPULoad,_T("ReadCPULoad"))
  134.     WRITEDW(showDiagram,_T("ShowDiagram"))
  135.     WRITEDW(cpuInterval,_T("UpdateInterval"))
  136.     WRITEDW(freqScaling,_T("FrequenceScaling"))
  137.     WRITEDW(maxSpeed,_T("CalculatedMaxSpeed"))
  138.     WRITEDW(showBattery,_T("ShowBattery"))
  139.     WRITEDW(batteryMethod,_T("BatteryMethod"))
  140.     WRITEDW(batteryIndicator,_T("BatteryIndicator"))
  141.     WRITEDW(chargeIndicator,_T("ChargeIndicator"))
  142.     WRITEDW(speedIcon,_T("TraySpeed"))
  143.     WRITEDW(loadIcon,_T("TrayLoad"))
  144.     WRITEDW(iconColor1,_T("IconColor1"))
  145.     WRITEDW(iconColor2,_T("IconColor2"))
  146.     WRITEDW(iconTransparent,_T("IconTransparent"))
  147.   }
  148.   else
  149.     return false;
  150.  
  151.   key.Close();
  152.  
  153.   return true;
  154. }
  155.  
  156.